//
//  LoginVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/29.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "LoginVC.h"
#import "LoginVM.h"
#import "TabBarViewController.h"
#import "AppDelegate.h"
#import "HomeVC.h"
#import "NewPasswordVC.h"
#import "SettingContentVC.h"
#import "SettingVC.h"
#import "MyVC.h"
@interface LoginVC ()
@property (weak, nonatomic) IBOutlet UITextField *textAccount;
@property (weak, nonatomic) IBOutlet UITextField *textPassword;
@property (weak, nonatomic) IBOutlet UIButton *btnLogin;
@property (weak, nonatomic) IBOutlet UIButton *btnRegistered;
@property (weak, nonatomic) IBOutlet UIImageView *logo;

@end

@implementation LoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"登录";
//    [UserModel clean];
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    self.view.backgroundColor=[UIColor whiteColor];
    _btnLogin.layer.cornerRadius=25;
    _btnLogin.layer.masksToBounds=YES;
    self.logo.layer.masksToBounds=YES;
    self.logo.layer.cornerRadius=12;
    _btnRegistered.layer.shadowColor=DEFAULTTEXTGRAYCOLOR.CGColor;
    _btnRegistered.layer.shadowOpacity=.3;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

- (void)backClick{
    id viewCtrl=self.navigationController.viewControllers[self.navigationController.viewControllers.count-2];
    if (!([viewCtrl isMemberOfClass:[NewPasswordVC class]]||[viewCtrl isMemberOfClass:[SettingContentVC class]]||[viewCtrl isMemberOfClass:[SettingVC class]]||[viewCtrl isMemberOfClass:[MyVC class]])) {
        [super backClick];
    }else{
        
        
        [self.navigationController popToRootViewControllerAnimated:YES];

        
    }

}

- (IBAction)login:(UIButton *)sender {
    if (_textAccount.text.length<1) {
        [SVProgressHUD showErrorWithStatus:@"请输入帐号"];
        return;
    }
    if (_textPassword.text.length<1) {
        [SVProgressHUD showErrorWithStatus:@"请输入密码"];
    }
    sender.userInteractionEnabled=NO;
    WS(weakSelf);
    [SVProgressHUD show];
    [[LoginVM manage] loginWithAccount:_textAccount.text andPassword:_textPassword.text andSuccess:^(id returnValue) {
        [weakSelf backClick];
        [SVProgressHUD dismiss];
    } andFail:^(NSString *errorMessage, NSError *error) {
        sender.userInteractionEnabled=YES;
    }];
}

- (IBAction)showPassword:(UIButton *)sender {
    sender.selected=!sender.isSelected;
    _textPassword.secureTextEntry=!sender.isSelected;
}

- (IBAction)forgetPassword:(UIButton *)sender {
}
- (IBAction)registered:(UIButton *)sender {
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
